﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:ctrl="clr-namespace:Tum.PDE.LanguageDSL.Visualization.View.Controls"
                    xmlns:conv="clr-namespace:Tum.PDE.LanguageDSL.Visualization.Converters">
    <ResourceDictionary.MergedDictionaries>
        
        <!--- misc dictionaries -->
        <ResourceDictionary Source="MenuItemStyle.xaml"/>
        <ResourceDictionary Source="Expander.xaml"/>

        <!--- element dictionaries -->
        <ResourceDictionary Source="DomainModelElements.xaml"/>

        <!--- connection dictionaries -->
        <ResourceDictionary Source="DomainModelConnections.xaml"/>
       
    </ResourceDictionary.MergedDictionaries>

    <conv:ToCollectionConverter x:Key="ToCollectionConverter"/>


    <!-- Class shape nodes control style.-->
    <DataTemplate x:Key="ShapeNodesTemplate">
        <ContentControl Style="{DynamicResource ClassShapeNodeStyle}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="5" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>

                <ctrl:DesignerItem Grid.Row="0" Style="{StaticResource ClassShapeMappingConnection}" Margin="0,0,0,0"/>
                <ctrl:DesignerItem Grid.Row="1" Style="{StaticResource ModelTreeClassShapeElement}" />
            </Grid>
        </ContentControl>
    </DataTemplate>
    <Style TargetType="{x:Type ContentControl}" x:Key="ShapeNodesControlStyle">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ContentControl}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <!-- Row for reference line-->
                            <RowDefinition Height="15"/>

                            <!-- Row for the actual elements-->
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>

                        <!-- Connecting Line for reference rs -->
                        <!-- only needed should we have more on different levels-->
                        <Rectangle x:Name="VerLn_Ref" Height="0" Width="25" VerticalAlignment="Top" HorizontalAlignment="Left" Stroke="Gray" Grid.Row="0" Grid.Column="0" SnapsToDevicePixels="true"/>

                        <ItemsControl Margin="0,0,0,0" Grid.Row="1" Grid.Column="0" x:Name="ItemsControlShapeNodes" ItemsSource="{Binding Path=ShapeClassNodes, Mode=OneWay}" ItemTemplate="{StaticResource ShapeNodesTemplate}">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel Orientation="Horizontal"/>
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                        </ItemsControl>
                    </Grid>

                    <ControlTemplate.Triggers>
                        <!-- Triggers for hiding nodes. -->
                        <DataTrigger Binding="{Binding Path=IsShapeMappingTreeExpanded}" Value="False">
                            <Setter TargetName="ItemsControlShapeNodes" Property="Visibility" Value="Collapsed"/>
                            <Setter TargetName="VerLn_Ref" Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>

                        <!-- Toggle button hiding connection line. -->
                        <DataTrigger Binding="{Binding Path=HasShapeMappingNodes}" Value="False">
                            <Setter TargetName="VerLn_Ref" Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style TargetType="{x:Type ContentControl}" x:Key="ClassShapeNodeStyle">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ContentControl}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>

                        <!-- Connecting Lines -->
                        <Rectangle x:Name="VerLn" Height="1" Stroke="Gray" Grid.Row="0" Grid.ColumnSpan="2" SnapsToDevicePixels="true"/>
                        <ContentPresenter Margin="0,0,0,0" x:Name="ItemsHost" Grid.Row="1" Grid.Column="1" Grid.RowSpan="2"/>
                    </Grid>

                    <ControlTemplate.Triggers>
                        <!-- This trigger changes the connecting lines if the item is the last in the list -->
                        <DataTrigger Binding="{Binding Path=IsLastNode}" Value="true">
                            <Setter TargetName="VerLn" Property="Width" Value="25"/>
                            <Setter TargetName="VerLn" Property="HorizontalAlignment" Value="Left"/>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- Relationship shape nodes control style.-->
    <DataTemplate x:Key="ShapeRSNodesTemplate">
        <ContentControl Style="{DynamicResource ReferenceRelationshipShapeNodeStyle}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="110" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <ctrl:DesignerItem Grid.Column="0" Style="{StaticResource RelationshipShapeMappingConnection}" Margin="0,0,0,0"/>
                <ctrl:DesignerItem Grid.Column="1" Style="{StaticResource ModelTreeRelationshipShapeElement}" />
            </Grid>
        </ContentControl>
    </DataTemplate>
    <Style TargetType="{x:Type ContentControl}" x:Key="ShapeRSNodesControlStyle">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ContentControl}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <!-- Column for reference line-->
                            <ColumnDefinition Width="30"/>
                            <!-- Column for the actual elements-->
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <!-- Row for reference relationship-->
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>

                        <!-- Connecting Line for reference rs -->
                        <Rectangle x:Name="VerLn_Ref" Height="0" Width="1" VerticalAlignment="Stretch" HorizontalAlignment="Right" Stroke="Gray" Grid.Row="0" Grid.Column="0" SnapsToDevicePixels="true"/>
                        <!-- only needed should we have more on different levels-->
                        <ItemsControl Margin="-90,0,0,0" Grid.Row="0" Grid.Column="1" x:Name="ItemsControlShapeRSNodes" ItemsSource="{Binding Path=ShapeRelationshipNodes}" ItemTemplate="{StaticResource ShapeRSNodesTemplate}"/>
                    </Grid>

                    <ControlTemplate.Triggers>
                        <!-- Triggers for hiding nodes. -->
                        <DataTrigger Binding="{Binding Path=IsShapeMappingTreeExpanded}" Value="False">
                            <Setter TargetName="ItemsControlShapeRSNodes" Property="Visibility" Value="Collapsed"/>
                            <Setter TargetName="VerLn_Ref" Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>

                        <!-- Toggle button hiding connection line. -->
                        <DataTrigger Binding="{Binding Path=HasShapeMappingNodes}" Value="False">
                            <Setter TargetName="VerLn_Ref" Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style TargetType="{x:Type ContentControl}" x:Key="ReferenceRelationshipShapeNodeStyle">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ContentControl}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>

                        <!-- Connecting Lines -->
                        <Rectangle x:Name="VerLn" Width="1" Stroke="Gray" Grid.Column="0" Margin="89,0,0,0" Grid.RowSpan="2" SnapsToDevicePixels="true"/>

                        <ContentPresenter Margin="-69,0,0,0" x:Name="ItemsHost" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2"/>
                    </Grid>

                    <ControlTemplate.Triggers>
                        <!-- This trigger changes the connecting lines if the item is the last in the list -->
                        <DataTrigger Binding="{Binding Path=IsLastNode}" Value="true">
                            <Setter TargetName="VerLn" Property="Height" Value="20"/>
                            <Setter TargetName="VerLn" Property="VerticalAlignment" Value="Top"/>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- Root elements template. Root nodes, embedding nodes and relationship nodes are displayed here as basically they
         all represent a domain class. For inheritance nodes we duplicate this template and extend it to display the connections.-->
    <DataTemplate x:Key="RootElementsTemplate">
        <StackPanel Orientation="Vertical">
            <!-- ClassElement representing the DomainClass-->
            <StackPanel Orientation="Horizontal">
                <ctrl:DesignerItem x:Name="ClassElement" Margin="10,0,0,0" HorizontalAlignment="Left" Style="{StaticResource DomainClassStyle}"/>
                <ContentControl Style="{DynamicResource ShapeNodesControlStyle}" />
            </StackPanel>
            <ContentControl Style="{DynamicResource RootItemsControlStyle}" />
        </StackPanel>
    </DataTemplate>

    <!-- Inheritance elements ItemsControl style.-->
    <Style TargetType="{x:Type ContentControl}" x:Key="InheritanceItemsControlStyle">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ContentControl}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>

                        <!-- Connecting Lines -->
                        <Rectangle x:Name="VerLn" Width="1" Stroke="Silver" Grid.Column="0" Margin="77,0,0,0" Grid.RowSpan="2" SnapsToDevicePixels="true"/>

                        <ContentPresenter Margin="-77,0,0,0" x:Name="ItemsHost" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <!-- This trigger changes the connecting lines if the item is the last in the list -->
                        <DataTrigger Binding="{Binding Path=IsLastNode}" Value="true">
                            <Setter TargetName="VerLn" Property="Height" Value="30"/>
                            <Setter TargetName="VerLn" Property="VerticalAlignment" Value="Top"/>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- Inheritance elements template. It only extends the root elements template by also displaying the inheritance connection. -->
    <DataTemplate x:Key="InheritanceElementsTemplate">
        <ContentControl Style="{StaticResource InheritanceItemsControlStyle}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="110" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <!-- Inheritance connection, connection the base class with the derived class. -->
                <ctrl:DesignerItem Margin="39,0,0,0" Grid.Column="0" Style="{StaticResource InheritedConnectionStyle}"/>

                <ItemsControl Grid.Column="1" VerticalAlignment="Top" ItemsSource="{Binding Path=., Converter={StaticResource ToCollectionConverter}}" ItemTemplate="{StaticResource RootElementsTemplate}" />
            </Grid>
        </ContentControl>
    </DataTemplate>

    <!-- Style for embedding items control. -->
    <Style TargetType="{x:Type ContentControl}" x:Key="EmbeddingRelationshipNodeStyle">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ContentControl}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>

                        <!-- Connecting Lines -->
                        <Rectangle x:Name="VerLn" Width="1" Stroke="Black" Grid.Column="0" Margin="70,0,0,0" Grid.RowSpan="2" SnapsToDevicePixels="true"/>

                        <ContentPresenter Margin="-70,0,0,0" x:Name="ItemsHost" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2"/>
                    </Grid>

                    <ControlTemplate.Triggers>
                        <!-- This trigger changes the connecting lines if the item is the last in the list -->
                        <DataTrigger Binding="{Binding Path=IsLastNode}" Value="true">
                            <Setter TargetName="VerLn" Property="Height" Value="30"/>
                            <Setter TargetName="VerLn" Property="VerticalAlignment" Value="Top"/>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- Template for displaying embedding relationships. It also contains the corresponding connection. -->
    <DataTemplate x:Key="EmbeddingRSNodesTemplate">
        <ContentControl Style="{StaticResource EmbeddingRelationshipNodeStyle}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="140" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <ctrl:DesignerItem Grid.Column="0" DataContext="{Binding Path=Source, Mode=OneWay}" Style="{StaticResource EmbeddingRelationshipSource}"/>

                <StackPanel Margin="0,0,0,0" Grid.Column="1" Orientation="Horizontal" x:Name="StackPanelEmbedding">
                    <ctrl:DesignerItem x:Name="EmbeddingElement" Margin="10,0,0,0" VerticalAlignment="Top" Style="{StaticResource EmbeddingRelationshipStyle}" />
                    <ctrl:DesignerItem x:Name="EmbeddingConTarget" DataContext="{Binding Path=Target, Mode=OneWay}" Style="{StaticResource EmbeddingRelationshipTarget}"/>
                    <ItemsControl Margin="90,0,0,0" x:Name="EmbeddingNodesItemsControl" VerticalAlignment="Top" ItemsSource="{Binding Path=EmbeddingNodes, Mode=OneWay}" ItemTemplate="{StaticResource RootElementsTemplate}"/>
                </StackPanel>
            </Grid>
        </ContentControl>
    </DataTemplate>    
       
    <!-- Style for reference items control. -->
    <Style TargetType="{x:Type ContentControl}" x:Key="ReferenceRelationshipNodeStyle">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ContentControl}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>

                        <!-- Connecting Lines -->
                        <Rectangle x:Name="VerLn" Width="1" Stroke="#FFCF9312" Grid.Column="0" Margin="74,0,0,0" Grid.RowSpan="2" SnapsToDevicePixels="true"/>

                        <ContentPresenter Margin="-74,0,0,0" x:Name="ItemsHost" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2"/>
                    </Grid>

                    <ControlTemplate.Triggers>
                        <!-- This trigger changes the connecting lines if the item is the last in the list -->
                        <DataTrigger Binding="{Binding Path=IsLastNode}" Value="true">
                            <Setter TargetName="VerLn" Property="Height" Value="30"/>
                            <Setter TargetName="VerLn" Property="VerticalAlignment" Value="Top"/>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- Template for displaying reference relationships. It also contains the corresponding connection as well as the relationship shapes if there are any. -->
    <DataTemplate x:Key="ReferenceRSNodesTemplate">
        <ContentControl Style="{StaticResource ReferenceRelationshipNodeStyle}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="160" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <ctrl:DesignerItem DataContext="{Binding Path=Source, Mode=OneWay}" Grid.Column="0" Margin="19,0,0,0" Style="{StaticResource ReferenceRelationshipSource}"/>

                <StackPanel Margin="0,0,0,0" Grid.Column="1" Orientation="Horizontal" x:Name="StackPanelReferencing">
                    <StackPanel Orientation="Vertical">
                        <ctrl:DesignerItem x:Name="ReferenceElement" Margin="10,0,0,0" VerticalAlignment="Top" Style="{StaticResource ReferenceRelationshipStyle}"/>

                        <!--  Referencing relationships can have shape representations. These are displayed via this items control. -->
                        <ContentControl Style="{StaticResource ShapeRSNodesControlStyle}" />
                        <!--<ItemsControl x:Name="ItemsControlShapeRSNodes" Margin="0,0,0,0" VerticalAlignment="Top" ItemsSource="{Binding Path=ShapeRelationshipNodes}" ItemTemplate="{StaticResource ShapeRSNodesTemplate}"/>-->
                    </StackPanel>
                    <ctrl:DesignerItem DataContext="{Binding Path=Target, Mode=OneWay}" Style="{StaticResource ReferenceRelationshipTarget}"/>
                    <ItemsControl Margin="90,0,0,0" VerticalAlignment="Top" ItemsSource="{Binding Path=ReferenceNodes}" ItemTemplate="{StaticResource RootElementsTemplate}"/>
                </StackPanel>
            </Grid>
        </ContentControl>
    </DataTemplate>
    
    <!-- Root elements ItemsControl style.-->
    <Style TargetType="{x:Type ContentControl}" x:Key="RootItemsControlStyle">
        <Style.Resources>
            <!-- Connection symbols. -->
            <Style x:Key="DiamondSymbolBaseStyle" TargetType="Path">
                <Setter Property="Fill" Value="#888"/>
                <Setter Property="Stretch" Value="Fill"/>
            </Style>
            <Style x:Key="ArrowSymbolBaseStyle" TargetType="Path">
                <Setter Property="Fill" Value="#FFF"/>
                <Setter Property="Stroke" Value="Black" />
                <Setter Property="StrokeThickness" Value="0.6" />
                <Setter Property="Stretch" Value="Fill"/>
            </Style>

            <Style x:Key="Arrow" TargetType="Path" BasedOn="{StaticResource ArrowSymbolBaseStyle}">
                <Setter Property="Data" Value="M0,0 8,4 0,8 Z"/>
            </Style>
            <Style x:Key="Diamond" TargetType="Path" BasedOn="{StaticResource DiamondSymbolBaseStyle}">
                <Setter Property="Data" Value="M-5,0 0,-5 5,0 0,5 Z"/>
            </Style>

            <Style x:Key="ArrowGridStyle" TargetType="Grid">
                <Setter Property="Width" Value="10"/>
                <Setter Property="Height" Value="10"/>
                <Setter Property="RenderTransform">
                    <Setter.Value>
                        <TranslateTransform X="-5.5" Y="-2"/>
                    </Setter.Value>
                </Setter>
            </Style>
        </Style.Resources>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ContentControl}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <!-- Column for inheritance line-->
                            <ColumnDefinition Width="38"/>
                            <!-- Column for reference line-->
                            <ColumnDefinition Width="17"/>
                            <!-- Column for embedding line-->
                            <ColumnDefinition Width="15"/>
                            <!-- Column for the actual elements-->
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <!-- Row for embedding relationship-->
                            <RowDefinition Height="Auto"/>
                            <!-- Row for reference relationship-->
                            <RowDefinition Height="Auto"/>
                            <!-- Row for inheritance relationship-->
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>

                        <!-- Connecting Line for embedding rs -->
                        <Rectangle x:Name="VerLn_Emb" Height="30" VerticalAlignment="Top" HorizontalAlignment="Right" Width="1" Stroke="Black" Grid.Row="0" Grid.Column="2" SnapsToDevicePixels="true"/>
                        <!-- Diamond symbol representing an identification of the embedding relation-->
                        <ctrl:SymbolCanvas x:Name="Symbol_Emb"  Grid.Row="0" VerticalAlignment="Top" Grid.Column="2" HorizontalAlignment="Right">
                            <Grid Style="{StaticResource ArrowGridStyle}" SnapsToDevicePixels="true">
                                <Path Name="PART_SourceAnchorPath" Style="{StaticResource Diamond}"/>
                                <Grid.LayoutTransform>
                                    <RotateTransform Angle="90"/>
                                </Grid.LayoutTransform>
                            </Grid>
                        </ctrl:SymbolCanvas>
                        <ItemsControl Margin="-71,0,0,0" Grid.Row="0" Grid.Column="3" x:Name="ItemsControlEmbeddingRSNodes" ItemsSource="{Binding Path=EmbeddingRSNodes}" ItemTemplate="{StaticResource EmbeddingRSNodesTemplate}"/>

                        <!-- Connecting Line for reference rs -->
                        <Rectangle x:Name="VerLn_Ref" Width="1" VerticalAlignment="Stretch" HorizontalAlignment="Right" Stroke="#FFCF9312" Grid.Row="0" Grid.Column="1" SnapsToDevicePixels="true"/>
                        <ItemsControl Margin="-90,0,0,0" Grid.Row="1" Grid.Column="3" x:Name="ItemsControlReferenceRSNodes" ItemsSource="{Binding Path=ReferenceRSNodes}" ItemTemplate="{StaticResource ReferenceRSNodesTemplate}"/>

                        <!-- Connecting Line for inheritance rs -->
                        <Rectangle x:Name="VerLn_Inh" Width="1" VerticalAlignment="Stretch" HorizontalAlignment="Right" Stroke="Silver" Grid.Row="0" Grid.RowSpan="2" Grid.Column="0" SnapsToDevicePixels="true"/>
                        <!-- Symbol representing an identification of the inheritance relation-->
                        <ctrl:SymbolCanvas x:Name="Symbol_Inh"  Grid.Row="0" VerticalAlignment="Top" Grid.Column="0" HorizontalAlignment="Right">
                            <Grid Style="{StaticResource ArrowGridStyle}" SnapsToDevicePixels="true">
                                <Path Name="PART_SourceAnchorPathArrow" Style="{StaticResource Arrow}"/>
                                <Grid.LayoutTransform>
                                    <RotateTransform Angle="-90"/>
                                </Grid.LayoutTransform>
                            </Grid>
                        </ctrl:SymbolCanvas>
                        <ItemsControl Margin="-110,0,0,0" Grid.Row="2" Grid.Column="3" x:Name="ItemsControlInheritanceNodes" ItemsSource="{Binding Path=InheritanceNodes}" ItemTemplate="{StaticResource InheritanceElementsTemplate}"/>
                    </Grid>

                    <ControlTemplate.Triggers>
                        <!-- Triggers for hiding nodes. -->
                        <DataTrigger Binding="{Binding Path=IsEmbeddingTreeExpanded}" Value="False">
                            <Setter TargetName="ItemsControlEmbeddingRSNodes" Property="Visibility" Value="Collapsed"/>
                            <Setter TargetName="VerLn_Emb" Property="Visibility" Value="Collapsed"/>
                            <Setter TargetName="Symbol_Emb" Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=IsInheritanceTreeExpanded}" Value="False">
                            <Setter TargetName="ItemsControlInheritanceNodes" Property="Visibility" Value="Collapsed"/>
                            <Setter TargetName="VerLn_Inh" Property="Visibility" Value="Collapsed"/>
                            <Setter TargetName="Symbol_Inh" Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=IsReferenceTreeExpanded}" Value="False">
                            <Setter TargetName="ItemsControlReferenceRSNodes" Property="Visibility" Value="Collapsed"/>
                            <Setter TargetName="VerLn_Ref" Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=IsShapeMappingTreeExpanded}" Value="False">
                            <!--<Setter TargetName="ItemsControlShapeClassNodes" Property="Visibility" Value="Collapsed"/>-->
                        </DataTrigger>

                        <!-- Toggle button hiding connection line. -->
                        <DataTrigger Binding="{Binding Path=HasEmbeddingRSNodes}" Value="False">
                            <Setter TargetName="VerLn_Emb" Property="Visibility" Value="Collapsed"/>
                            <Setter TargetName="Symbol_Emb" Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=HasInheritanceNodes}" Value="False">
                            <Setter TargetName="VerLn_Inh" Property="Visibility" Value="Collapsed"/>
                            <Setter TargetName="Symbol_Inh" Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=HasReferenceNodes}" Value="False">
                            <Setter TargetName="VerLn_Ref" Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=HasShapeMappingNodes}" Value="False">
                            <!--<Setter TargetName="ShapeMappingToggleButton" Property="Visibility" Value="Collapsed"/>-->
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
        
    <Style TargetType="{x:Type ItemsControl}" x:Key="RootItemsControl">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ItemsControl}">
                    <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                        <ctrl:DesignerCanvas SelectedItems="{Binding Path=SelectedItems, Mode=TwoWay}"
                                             ContextMenuOptions="{Binding Path=Operations, Mode=OneWay}"
                                             HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                                             Background="Transparent"
                                             Focusable="True">
                            <ctrl:DesignerCanvas.InputBindings>
                                <KeyBinding Key="Delete" Command="{Binding Path=DeleteCommand}"/>
                            </ctrl:DesignerCanvas.InputBindings>
                            <ctrl:DesignerCanvas.ContextMenu>
                                <ContextMenu ItemContainerStyleSelector="{StaticResource ContextMenuItemStyleSelector}"/>
                            </ctrl:DesignerCanvas.ContextMenu>
                            <ItemsPresenter Margin="0,0,1000,2000"/>
                        </ctrl:DesignerCanvas>
                    </ScrollViewer>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>    
</ResourceDictionary>